﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_PERMISSION.Base;

namespace ERP_RORZE_PRODUCT.Product.MonthlyCharge
{
    public partial class frm_MonthlyChargeUpdate : DevExpress.XtraEditors.XtraForm
    {
        MonthlyLaborCharge b = new MonthlyLaborCharge();
        MonthlyMachineCharge d = new MonthlyMachineCharge();
        ClsMonthlyExpenceDAO clsMonthlyExpence = new ClsMonthlyExpenceDAO();
        private LogUtils log;
        DataTable dt;

        public frm_MonthlyChargeUpdate()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        private void btnLaborchargeupdate_Click(object sender, EventArgs e)
        {
            b.Month = int.Parse(dateDate.Value.ToString("MM"));
            b.Year = int.Parse(dateDate.Value.ToString("yyyy"));
            dt = clsMonthlyExpence.GetAllMonthlyLaborByDate(b);
            int i = 0;
            foreach (DataRow r in dt.Rows)
            {
                i++;
            }
            if (i > 0)
            {
                MessageBox.Show("Chi phí của tháng này đã update rồi. Hãy xem lại");
            }
            else
            {
                MonthlyLaborCharge c = new MonthlyLaborCharge();
                c.Month = int.Parse(dateDate.Value.ToString("MM"));
                c.Year = int.Parse(dateDate.Value.ToString("yyyy"));
                clsMonthlyExpence.InsertLaborChargeUpdate(c);

                //write Log
                log.Table = LogConstant.Table.Product.MonthlyLaborCharge;
                log.Task = LogConstant.Task.Insert;
                log.Description = "Month: " + c.Month + "; Year: " + c.Year;
                log.WriteLog();

                MessageBox.Show("Đã xong!");

            }


        }

        private void btnMachineChargeUpdate_Click(object sender, EventArgs e)
        {
            d.Month = int.Parse(dateDate.Value.ToString("MM"));
            d.Year = int.Parse(dateDate.Value.ToString("yyyy"));
            dt = clsMonthlyExpence.GetAllMonthlyMachineByDate(d);
            int i = 0;
            foreach (DataRow r in dt.Rows)
            {
                i++;
            }
            if (i > 0)
            {
                MessageBox.Show("Chi phí của tháng này đã update rồi. Hãy xem lại");
            }
            else
            {
                d.Month = int.Parse(dateDate.Value.ToString("MM"));
                d.Year = int.Parse(dateDate.Value.ToString("yyyy"));
                clsMonthlyExpence.InsertMachineChargeUpdate(d);

                //write Log
                log.Table = LogConstant.Table.Product.MonthlyMachineCharge;
                log.Task = LogConstant.Task.Insert;
                log.Description = "Month: " + d.Month + "; Year: " + d.Year;
                log.WriteLog();

                MessageBox.Show("Đã xong!");

            }
        }
    }
}
